## Figure D.1: Positive Relationship between Corporate PAC Donations and Lobbying
# Expenses, between 2008 and 2018:: --------------------------------------------

## Instructions ----------------------------------------------------------------
# Step 1: Adjust MAIN_DIR to main folder
# Step 2: Adjust DATA_DIR to where data is is located
# Step 3: Adjust FIG_DIR to where output folder is
# Step 4: Run entire script
## setup -----------------------------------------------------------------------

# clean slate
rm(list = ls())

library(tidyverse)

# set directory
MAIN_DIR <- "C:/Users/js.egb/Dropbox/campaign-lobby-paper/replication_package"

# set data folder
DATA_DIR <-  paste(MAIN_DIR, "/data/", sep = "")

# set output folder
FIG_DIR <- paste(MAIN_DIR, "/output/", sep = "")

# file to be read in
file_in1 <- paste0(DATA_DIR, "lobby_pac_1999_2000_replication.csv") # file to be input

### 3. Scatter Plot A La Ansolabehere et al 2002:
lob_pac <- read.csv(file_in1, stringsAsFactors = FALSE)


# CUBE ROOT Transformation
lob_pac_cube <- data.frame(lob = lob_pac$lob_amount[lob_pac$lob_amount>0 & lob_pac$pac_amount>0]^(1/3),
                           pac = lob_pac$pac_amount[lob_pac$pac_amount>0 & lob_pac$lob_amount>0]^(1/3),
                           org = lob_pac$org_type_joint[lob_pac$pac_amount>0 & lob_pac$lob_amount>0],
                           stringsAsFactors = FALSE)

pdf(paste0(FIG_DIR, "/figure_g1.pdf"), width = 11, height = 8)
par(mfrow = c(2,2))

plot(lob_pac$pac_amount[lob_pac$org_type_joint == "T"]^(1/3), lob_pac$lob_amount[lob_pac$org_type_joint == "T"]^(1/3), pch = 16, cex = .5, las = 0.8, font.lab = 2, axes=FALSE,
     main = "Trade Associations",  ylim = c(0,650), xlim = c(0,250),
     xlab = "PAC Dollars (cube-root)", ylab = "Lobbying Dollars (cube-root)")
grid(col = "lightgrey", lty = "solid")
text(x = 40, y = 600, labels = expression(paste(beta, " = ", "0.8")), cex = 1.3)
axis(1, at = seq(0, 300, 50))
axis(2, at = seq(0, 700, 100))
abline(lm(lob ~ pac, data = lob_pac_cube[lob_pac_cube$org == "T",]), col = "black", lwd = 2)

plot(lob_pac$pac_amount[lob_pac$org_type_joint == "L"]^(1/3), lob_pac$lob_amount[lob_pac$org_type_joint == "L"]^(1/3), pch = 16, cex = .5, las = 0.8, font.lab = 2, axes=FALSE,
     main = "Labor Unions",  ylim = c(0,650), xlim = c(0,250),
     xlab = "PAC Dollars (cube-root)", ylab = "Lobbying Dollars (cube-root)")
grid(col = "lightgrey", lty = "solid")
text(x = 40, y = 600, labels = expression(paste(beta, " = ", "0.6")), cex = 1.3)
axis(1, at = seq(0, 300, 50))
axis(2, at = seq(0, 700, 100))
abline(lm(lob ~ pac, data = lob_pac_cube[lob_pac_cube$org == "L",]), col = "black", lwd = 2)

plot(lob_pac$pac_amount[lob_pac$org_type_joint == "C"]^(1/3), lob_pac$lob_amount[lob_pac$org_type_joint == "C"]^(1/3), pch = 16, cex = .5, las = 0.8, font.lab = 2, axes=FALSE,
     main = "Corporations",  ylim = c(0,650), xlim = c(0,250),
     xlab = "PAC Dollars (cube-root)", ylab = "Lobbying Dollars (cube-root)")
grid(col = "lightgrey", lty = "solid")
text(x = 40, y = 600, labels = expression(paste(beta, " = ", "2")), cex = 1.3)
axis(1, at = seq(0, 300, 50))
axis(2, at = seq(0, 700, 100))
abline(lm(lob ~ pac, data = lob_pac_cube[lob_pac_cube$org == "C",]), col = "black", lwd = 2)

plot(lob_pac$pac_amount[lob_pac$org_type_joint == "M"]^(1/3), lob_pac$lob_amount[lob_pac$org_type_joint == "M"]^(1/3), pch = 16, cex = .5, las = 0.8, font.lab = 2, axes=FALSE,
     main = "Membership Organizations",  ylim = c(0,650), xlim = c(0,250),
     xlab = "PAC Dollars (cube-root)", ylab = "Lobbying Dollars (cube-root)")
grid(col = "lightgrey", lty = "solid")
text(x = 40, y = 600, labels = expression(paste(beta, " = ", "1.6")), cex = 1.3)
axis(1, at = seq(0, 300, 50))
axis(2, at = seq(0, 700, 100))
abline(lm(lob ~ pac, data = lob_pac_cube[lob_pac_cube$org == "M",]), col = "black", lwd = 2)

dev.off()

